package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.model.CommonResult;
import com.atguigu.springcloud.model.Payment;
import com.atguigu.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Slf4j
public class PayController {
    @Resource
    private PaymentService paymentService;

    @PostMapping(value = "/payment/create")
    public CommonResult create(@RequestBody Payment payment){
        int result=paymentService.creat(payment);
        log.info("*****插入结果："+result);
        if(result>0){
            return new CommonResult(200,"插入数据库成功");
        }
        else{
            return new CommonResult(444,"插入数据库失败");
        }
    }

    @GetMapping(value = "/payment/get/{id}")
    public CommonResult getPaymentById(@PathVariable("id") Integer id){
        Payment payment=paymentService.getPaymentById(id);
        log.info("*****插入结果："+payment);

        if(null!=payment){
            return new CommonResult(200,"查询成功",payment);
        }
        else{
            return new CommonResult(444,"没有对应的记录，查询ID："+id,null);
        }
    }
}
